package us.sunrisemorning.mykancolle.mapdata;

import org.apache.commons.lang3.RandomUtils;

import com.alibaba.fastjson.JSONObject;

import us.sunrisemorning.mykancolle.config.GameData;

public abstract class BaseMapData {
    protected int maparea_id;
    protected int mapinfo_no;
    protected int no;
    protected int from_no;
    protected int next;
    protected int bosscell_no;
    protected int bosscomp;
    protected long userId;
    protected String mapname = "";
    protected int maplevel = 1;

    public abstract void moveNext();

    public abstract EnemyDeck getCurrentCellEnemyInfo();

    protected abstract int getEventKind();

    protected abstract int getEventId();

    public JSONObject getCurrentCellInfo() {
        JSONObject result = new JSONObject();
        this.addRashin(result, false);
        this.addMapId(result);
        return result;
    };

    public String getMapname() {
        return mapname;
    }
    
    public int getMaplevel() {
        return maplevel;
    }

    protected final void addRashin(JSONObject data, boolean isNeed) {
        if (isNeed) {
            data.put("rashin_flg", 1);
            data.put("rashin_id", RandomUtils.nextInt(1, 5));
        } else {
            data.put("rashin_flag", 0);
            data.put("rashin_id", 0);
        }
    }

    protected final void addMapId(JSONObject data) {
        JSONObject cell = GameData.getMapcellData(maparea_id * 10 + mapinfo_no).get(no);

        data.put("maparea_id", maparea_id);
        data.put("mapinfo_no", mapinfo_no);
        data.put("no", no);
        data.put("color_no", cell.getInteger("api_color_no"));
        data.put("event_id", getEventId());
        data.put("event_kind", getEventKind());
        data.put("next", next);
        data.put("bosscell_no", bosscell_no);
        data.put("bosscomp", bosscomp);
        data.put("airsearch", getAirsearch());
        data.put("from_no", from_no);
    }

    protected JSONObject getAirsearch() {
        JSONObject result = new JSONObject();
        result.put("plane_type", 0);
        result.put("result", 0);
        return result;
    }
}
